package wangyifan;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;

public class DoubleColorBall {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // 用户输入红球号码
        List<Integer> redNumbers = new ArrayList<>();
        while (redNumbers.size() < 6) {
            System.out.println("请输入第 " + (redNumbers.size() + 1) + " 个红球号码，范围 1 - 33：");
            int number = scanner.nextInt();
            if (number >= 1 && number <= 33 && !redNumbers.contains(number)) {
                redNumbers.add(number);
            } else {
                System.out.println("输入无效，请输入一个 1 - 33 且不重复的数字。");
            }
        }

        // 用户输入蓝球号码
        int blueNumber = 0;
        while (true) {
            System.out.println("请输入蓝球号码，范围 1 - 16：");
            blueNumber = scanner.nextInt();
            if (blueNumber >= 1 && blueNumber <= 16) {
                break;
            } else {
                System.out.println("输入无效，请输入一个 1 - 16 的数字。");
            }
        }

        // 中奖红球号码
        List<Integer> winRedNumbers = new ArrayList<>();
        Random random = new Random();
        while (winRedNumbers.size() < 6) {
            int redNumber = random.nextInt(33) + 1;
            if (!winRedNumbers.contains(redNumber)) {
                winRedNumbers.add(redNumber);
            }
        }

        // 中奖蓝球号码
        int winBlueNumber = random.nextInt(16) + 1;

        // 统计命中的红球和蓝球数量
        int redMatchCount = 0;
        for (int num : redNumbers) {
            if (winRedNumbers.contains(num)) {
                redMatchCount++;
            }
        }
        int blueMatchCount = (blueNumber == winBlueNumber) ? 1 : 0;

        // 把蓝球号码添加到红球号码列表后面
        List<Integer> userAllNumbers = new ArrayList<>(redNumbers);
        userAllNumbers.add(blueNumber);
        List<Integer> winAllNumbers = new ArrayList<>(winRedNumbers);
        winAllNumbers.add(winBlueNumber);

        // 输出中奖号码和用户投注号码
        System.out.println("中奖号码为：" + winAllNumbers);
        System.out.println("您投注号码为：" + userAllNumbers);

        System.out.println("您命中了 " + redMatchCount + " 个红色球号码，" + blueMatchCount + " 个蓝色球号码。");
        if (redMatchCount == 6 && blueMatchCount == 1) {
            System.out.println("恭喜您，中了一等奖！");
        } else if (redMatchCount == 6) {
            System.out.println("恭喜您，中了二等奖！");
        } else if (redMatchCount == 5 && blueMatchCount == 1) {
            System.out.println("恭喜您，中了三等奖！");
        } else if (redMatchCount == 5 || (redMatchCount == 4 && blueMatchCount == 1)) {
            System.out.println("恭喜您，中了四等奖！");
        } else if (redMatchCount == 4 || (redMatchCount == 3 && blueMatchCount == 1)) {
            System.out.println("恭喜您，中了五等奖！");
        } else if ((redMatchCount == 2 && blueMatchCount == 1) ||
                (redMatchCount == 1 && blueMatchCount == 1) ||
                (redMatchCount == 0 && blueMatchCount == 1)) {
            System.out.println("恭喜您，中了六等奖！");
        } else {
            System.out.println("很遗憾，您未中奖！");
        }

        scanner.close();
    }
}